package cn.ultrarisk.scadmin.manager.scheduler;

import cn.ultrarisk.scadmin.manager.biz.common.context.OperationType;
import cn.ultrarisk.scadmin.manager.biz.common.service.OperationLogService;
import cn.ultrarisk.scadmin.manager.biz.stat.service.SolrNodeStatService;
import cn.ultrarisk.scadmin.manager.biz.stat.service.SolrReplicaStatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

/**
 * HourStatScheduler
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/5/22
 * @since V1.0
 */
@Component
public class MonthStatScheduler {
    @Autowired
    private SolrNodeStatService solrNodeStatService;
    @Autowired
    private SolrReplicaStatService solrReplicaStatService;
    @Autowired
    private OperationLogService operationLogService;

    public void execute() throws Exception {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(System.currentTimeMillis()));
        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
        long time = calendar.getTimeInMillis();

        solrNodeStatService.deleteMonthStat(time);
        solrNodeStatService.buildMonthStat(time);

        solrReplicaStatService.deleteMonthStat(time);
        solrReplicaStatService.buildMonthStat(time);

        operationLogService.createBuildStatLog(OperationType.BUILD_MONTH_STAT);
    }
}
